package com.dhh.web.modules.user.domain;

import lombok.*;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Set;

/**
 * @Auther: dhh
 * @Date: 2018/11/20 10:42
 * @Email: fzlinjianhui@163.com
 * @Description:
 */
@Entity
@Table(name = "dhh_web_user")
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(length = 32)
    private String userId;

    @Column(unique = true,length = 20)
    @NotBlank(message = "用户名不能为空")
    @Size(min = 1,max = 20,message = "用户名在1到20位之间")
    private String username;

    @Column(unique = true,length = 100)
    @NotBlank(message = "密码不能为空")
    private String password;

    /**
     * 盐
     */
    private String salt;

    /**
     * 状态  0：禁用   1：正常
     */
    private Integer status;

    /**
     * 角色ID列表
     */
    @ManyToMany(fetch=FetchType.EAGER)
    @JoinTable(joinColumns=@JoinColumn(name="u_id"),inverseJoinColumns=@JoinColumn(name="r_id"))
    private Set<Role> roles;
}
